<template>
  <div class="list">
    <div class="content-head" style="margin-bottom: 20px;">
      <div class="sort-keys">
        <a-input placeholder="用户名/手机号" style="width: 180px;margin-right:10px;" v-model="key" allowClear :size="size"
          @input="onSearch" />
        <a-button :size="size" type="primary" @click="refreshData" style="margin-right:10px;">刷新</a-button>
      </div>
    </div>
    <a-table class="table" :rowKey="row => row.uuid" :dataSource="list" :pagination="pagination" :size="size">
      <a-table-column title="用户" width="40px">
        <template slot-scope="row">
          <div class="user">
            <img class="headimg" :src="row.user.headimg" alt="用户头像">

            <div class='right'>
              <div class="top">
                <span>{{ row.user.name }}</span>
                <a-icon class="gender-man" v-if="row.gender==='男'" type="man" />
                <a-icon class="gender-woman" v-else-if="row.gender==='女'" type="woman" />
              </div>
              <div class="bottom" style="margin-top: 4px;">

                <span class="marked-tag" :class="{actived: row.user.marked_at}">标记</span>
                <span>{{row.user.phone}}</span>

                <a-tag color="red" style="margin-left:10px;" v-if="row.user.status === 2">已拉黑</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_rb === 1">马甲</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_rb2 === 1">主播</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_liu === 1">老六</a-tag>
              </div>
              <span>{{ row.remark }}</span>
            </div>
          </div>
        </template>
      </a-table-column>
      <a-table-column title="变动数额" width="100px">
        <template slot-scope="row">
          <div v-if="row.type === 0" style="color: red;">
            - {{row.value}}
          </div>
          <div v-else style="color: #2BA246;">
             + {{row.value}}
          </div>
        </template>
      </a-table-column>
      <a-table-column title="变动描述" width="100px">
        <template slot-scope="row">
          <div>
            {{row.description }}
          </div>
           <div style="margin-top: 4px;">{{row.order_number}}</div>
        </template>
      </a-table-column>
      <a-table-column title="变动后数额" width="100px">
        <template slot-scope="row">
          <div>
            {{row.after}} 元
          </div>
        </template>
      </a-table-column>

      <a-table-column title="变动前数额" width="100px">
        <template slot-scope="row">
          <div>
            {{row.before}} 元
          </div>
        </template>
      </a-table-column>

      <a-table-column title="变动日期" dataIndex="created_at" width="80px">
        <template slot-scope="created_at">
          <span>{{ created_at | onlyDay }}</span>
        </template>
      </a-table-column>
    </a-table>

  </div>
</template>
<script>
  import moment from 'moment'
  import ISwitch from '@/components/ISwitch/ISwitch'

  export default {
    components: {
      ISwitch,
    },
    data() {
      return {
        list: [],
        page: 1,
        per_page: 10,
        total: 0,
        key: '',
        category_id: undefined,
        assetInfo: {

        },
        isExport: false
      }
    },
    watch: {
      params() {
        this.refreshData()
      },
      category_id() {
        this.refreshData()
      }
    },
    computed: {
      pagination() {
        return {
          defaultPageSize: this.per_page,
          defaultCurrent: this.page,
          total: this.total,
          onChange: (e) => {
            this.page = e
            this.fetchData()
          }
        }
      }
    },
    filters: {},
    created() {
      this.fetchData()
    },
    methods: {
      refreshData() {
        this.page = 1
        this.key = ''
        this.fetchData()
      },
      onSearch(e) {
		    this.page = 1
        this.fetchData()
      },
      fetchData() {
        this.isEdit = false
        this.$http.get(`luck-log`, {
          params: {
            ...this.params,
            page: this.page,
            per_page: this.per_page,
            key: this.key,
          }
        }).then(res => {
          this.list = res.data.list
          this.total = res.data.item_total
        }).finally(() => {
          this.loading = false
        })

      },

    }
  }
</script>
<style lang="scss" scoped>
  .marked-tag {
    border-radius: 50px;
    border: 1px solid #666;
    font-size: 10px;
    padding: 1px 6px;
    color: #666;
    cursor: pointer;
    margin-right: 6px;

    &.actived {
      background: #666;
      color: white;
    }
  }
  .value-font {
    font-weight: 500;
    font-size: 110%;
  }
  .content-head {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .table {
    .thumb {
      height: 60px;
      border-radius: 6px;
    }

    .content-image {
      height: 60px;
      width: 60px;
      margin-right: 10px;
      margin-bottom: 10px;
      object-fit: cover;
      border-radius: 10px;
      cursor: pointer;

      &:hover {
        opacity: 0.8;
      }
    }

    .user {
    display: flex;
    // flex-wrap: wrap;
    align-items: center;
    img {
      width: 38px;
      height: 38px;
      flex: 0 0 38px;
      border: 1px solid #e1e1e1;
      margin-right: 6px;
      border-radius: 50%;
      overflow: hidden;
    }
    .gender-man, .gender-woman {
      margin-left: 5px;
      font-size: 12px;
    }
    .gender-man {
      color: #409EFF;
    }
    .gender-woman {
      color: #F56C6C;
    }
  }
  }
</style>
